package cn.campus.util;

import cn.campus.pojo.article.vo.ResultVO;

/**
 * 创建响应结果ResultVO的工具类
 * Created by linyanbin on 2018/9/15.
 */
public class ResultVoUtils {

    private ResultVoUtils(){}

    /**
     * 成功响应方法，带数据
     * @param data
     * @return
     */
    public static ResultVO success(Object data) {
        ResultVO result = new ResultVO();
        result.setCode(0);
        result.setMsg("OK");
        result.setData(data);
        return result;
    }

    /**
     * 成功响应方法，不带数据
     * @return
     */
    public static ResultVO success() {
        return success(null);
    }

    /**
     * 失败响应方法，含参数：失败状态码及失败信息
     * @param code
     * @param msg
     * @return
     */
    public static ResultVO error(Integer code, String msg) {
        ResultVO result = new ResultVO();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
